/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package DBLayer;

import ModelLayer.Invoice;
import ModelLayer.Product;
import ModelLayer.SalesOrder;
import Prototypes.DataLayer;
import Prototypes.SalesOrderResultSetModelBinder;
import java.sql.*;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author Hedevilla
 */
public class DBInvoiceContainer extends DataLayer implements IInvoice {

    public DBInvoiceContainer()
    {
        super();

    }

        public boolean createInvoice(Invoice iv)
    {
        int noOfAffectedRows = -1;




        String query = "INSERT INTO WSSalesOrder VALUES('"
                + iv.getPaymentDate() + "','"
                + iv.getAmount() + "')";

        System.out.println(query);

        try
        {
            Statement stmt = dbConnection.createStatement();
            stmt.setQueryTimeout(5);
            noOfAffectedRows = stmt.executeUpdate(query);
            stmt.close();
        }
        catch (SQLException ex)
        {
            System.out.println("Insert exception in customer db; " + ex);
        }
        return noOfAffectedRows > 0;
    }

    public int getNewestInvoiceID()
    {

        ResultSet rs2 = null;
        int SalesOrderID = -1;
         String query = "SELECT MAX(InvoiceNo) FROM WSInvoice";

        System.out.println(query);

        try
        {
            Statement stmt = dbConnection.createStatement();
            stmt.setQueryTimeout(5);
            rs2 = stmt.executeQuery(query);

             if(rs2.next()) {
                SalesOrderID = rs2.getInt(1);
            }
            stmt.close();
        }
        catch (SQLException ex)
        {
            System.out.println("Insert exception in customer db; " + ex);
        }


        return SalesOrderID;

    }

}
